﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XCommunity.Users;
using System.Security.Principal;
using XCommunity.Frames;

namespace XCommunity.Forums
{
  /// <summary>
  /// 允许编辑自己的帖子权限
  /// </summary>
  public class AllowsMofityOwnPostPermission : IControlItem
  {
    #region IPermissionItem 成员

    public bool IsSatisfied( IPrincipal user, string action, params object[] frameObjects )
    {
      if ( action != "ModifyPost" )
        return false;

      var post = frameObjects.OfType<GeneralPostFrame>().Single();

      if ( post.IsTheme )
        return false;

      return user.Identity.IsSelf( post.Author );
    }

    public ControlItemType ControlType
    {
      get { return ControlItemType.Allow; }
    }

    public string Name
    {
      get { return "AllowsMofityOwnPost"; }
    }

    #endregion

  }
}
